import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
class Node {
    int val;
    Node next;
    Node random;

    public Node(int val) {
        this.val = val;
        this.next = null;
        this.random = null;
    }
}
public class Text {
    public static void main(String[] args) {
        HashSet<Integer> set =new HashSet<>();
        for (int i = 0; i < ; i++) {
            
        }
    }


    public Node copyRandomList(Node head) {
        HashMap<Node,Node> map =new HashMap<>();
        Node cur =head;
        while(cur!=null){
            Node node =new Node(cur.val);
            map.put(cur,node);
            cur=cur.next;
        }
        cur =head;
        while(cur!=null){
            map.get(cur).next =map.get(cur.next);
            map.get(cur).random =map.get(cur.random);
            cur =cur.next;
        }
        return map.get(head);
    }


    public int singleNumber2(int[] nums) {
        int ret =0;
        for(int i=0;i<nums.length;i++){
            ret=ret^nums[i];
        }
        return ret;
    }


    public int singleNumber5(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 1; i += 2) {
            if (nums[i] != nums[i + 1]) {
                return nums[i];
            }
        }
        return nums[nums.length - 1];
    }


    public int singleNumber4(int[] nums) {
        HashSet<Integer> set =new HashSet<>();
        int sum =0;
        int unquinesu=0;
        for(int i=0;i<nums.length;i++){
            if(!set.contains(nums[i])){
                set.add(nums[i]);
                unquinesu+=nums[i];
            }
            sum+=nums[i];
        }
        return unquinesu*2-sum;
    }


    public int singleNumber(int[] nums) {
        HashSet set =new HashSet<>();
        for(int i=0;i<nums.length;i++){
            if(set.contains(nums[i])){
                set.remove(nums[i]);
            }else{
                set.add(nums[i]);
            }
        }
        for(int i=0;i<nums.length;i++){
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }



    public int singleNumber1(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for(int i=0;i<nums.length;i++){
            if(set.contains(nums[i])){
                set.remove(nums[i]);
            }else{
                set.add(nums[i]);
            }
        }
        Iterator<Integer> iterator =set.iterator();
        while(iterator.hasNext()){
            return iterator.next();
        }
        return -1;
    }
}
